package control;

import java.util.Arrays;

public class LoopControl {

    public static void whileControl() {
        int i = 0;
        int sum = 0;
        while (i<=100) {
            sum+=i++;
        }
        System.out.println(sum);
        i = 0;
        sum = 0;
        do {
            sum+=i++;
        }while (i<=100);
        System.out.println(sum);
    }

    public static void forControl() {
        int temp = 0;
        boolean flag = true;
        int[] array = {1,6,2,7,9,3};

        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j < array.length-i-1; j++) {
                if(array[j] > array[j+1]) {
                    temp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = temp;
                    flag = false;
                }
            }
            if(flag) {
                break;
            }
        }
        System.out.println(Arrays.toString(array));

        int oddSum = 0;
        int evenSum = 0;
        for (int i = 0; i <= 100; i++) {
            if (i%2==0) {
                oddSum += i;
            }else{
                evenSum += i;
            }
        }
        System.out.println("偶数和:"+oddSum+"\n奇数和:"+evenSum);
    }

    public static void forPlus() {
        int[] numbers = {10,12,14,16,18};
        for (int temp : numbers) {
            System.out.println(temp);
        }
    }

    public static void multiple9_9() {
        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print(j+"*"+i+"="+j*i+" ");
            }
            System.out.println();
        }
    }

    public static void labelGoto() {
        int count = 0;
        outer:for (int i = 101;i <= 150;i++) {
            for (int j = 2; j < i/2; j++) {
                if (i%j==0) {
                    continue outer;
                }
            }
            System.out.print(i+" ");
        }
    }

    public static void main(String[] args) {
        forControl();
        forPlus();
        multiple9_9();
        labelGoto();
    }
}
